package com.whccb.apps.office.document.button;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ValueListener;
import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate;
import com.actionsoft.sdk.local.SDK;
import com.whccb.apps.office.document.ODConstant;
import com.whccb.apps.office.document.util.ODAppUtil;

/**
 * 套红
 * 
 * @author xqli
 * 
 */
public class UseRedHeaderFileButton extends ValueListener {

	@Override
	public String execute(ProcessExecutionContext ctx) throws Exception {
		String boName = "";// 通过流程参数得到bo名称
		Map<String, Object> paramMap = SDK.getProcessAPI().getVariables(
				ctx.getProcessInstance().getId());
		if (paramMap != null) {
			boName = paramMap.get("BONAME").toString();
		}
		if (StringUtils.isNotEmpty(boName)) {
			BO institutionBo = SDK.getBOAPI().getByProcess(boName,
					ctx.getProcessInstance().getId());
			if (institutionBo != null) {

				String recordTypeId = institutionBo.getString("RECORDTYPEID");
				return HtmlPageTemplate.merge(ODConstant.APP_ID,
						"gw.hongt.template.html", ODAppUtil
								.getRedHeaderFileParam(ctx.getUserContext(),
										recordTypeId));
			}
		}

		return null;
	}
}
